/*
 * @lc app=leetcode.cn id=1200 lang=typescript
 *
 * [1200] 最小绝对差
 */

// @lc code=start
function minimumAbsDifference(arr: number[]): number[][] {
    const sorted = [...arr].sort((a, b) => a - b);
    let min = Infinity;
    let cache: number[][] = [];
    for (let i = 1; i < sorted.length; i++) {
        const prev = sorted[i - 1];
        const element = sorted[i];

        const diff = element - prev;
        if (diff < min) {
            cache = [[prev, element]];
            min = diff;
        } else if (diff === min) {
            cache.push([prev, element]);
        }
    }
    return cache;
}
// @lc code=end
